<?php 
if(KT!='KhiThe') exit;
class products_model extends khithe_mysql
{	
	public function getMenuProducts($ParentID)
	{
		$ParentID = parent::checkStrMySQL($ParentID);
		$select = "SELECT * FROM ".categorys." WHERE ParentID = '".$ParentID."' AND `Status`='true' ORDER BY  `Order` ASC";
		parent::CloseConnection();
		return parent::SelectMySQL($select);
	}
	
	public function getSqlProducts($ParentID,$page,$limit)
	{
		$ParentID = parent::checkStrMySQL($ParentID);
		
		if($ParentID!=''){
			$strPID = " CategoryID='".$ParentID."'";
			$resultMenu = $this->getMenuProducts($ParentID);
			while( $rowMenu = mysql_fetch_assoc($resultMenu) )
			{
				$strPID = $strPID." OR CategoryID='".$rowMenu['ID']."'";		
			}
		}
		
		$str = $ParentID==""?"":" WHERE $strPID ";
		if($limit!=''){
			$page=($page==''?1:$page);
			$start = ($page - 1)* $limit; 
			$strlimit = "LIMIT $start, $limit";
		}
		else{
			$strlimit ='';
		}
		 
		
		$select = "SELECT * FROM ".products." ".$str."  AND `Status`='true' ORDER BY ID DESC ".$strlimit." ";
		parent::CloseConnection();
		return parent::SelectMySQL($select);
	}
	
	public function getMenu($ID)
	{
		$ID = parent::checkStrMySQL($ID);
		$select = "SELECT * FROM ".categorys." WHERE ID = '".$ID."' AND `Status`='true'";
		$query = parent::SelectMySQL($select);
		$row = mysql_fetch_assoc($query);
		
		return $row;
	}
	
	public function getIDSk($SeoKey)
	{
		$SeoKey = parent::checkStrMySQL($SeoKey);
		$select = "SELECT ID FROM ".categorys." WHERE SeoKey = '".$SeoKey."' AND `Status`='true'";
		$query = parent::SelectMySQL($select);
		$row = mysql_fetch_assoc($query);
		return $row['ID'];
	}
	
	public function getManufacturer($ID)
	{
		$select = "SELECT * FROM ".manufacturers." WHERE ID='".$ID."' ORDER BY `Order` ASC";
		$query = parent::SelectMySQL($select);
		$row = mysql_fetch_assoc($query);
		parent::CloseConnection();
		
		return $row;
	}
	
	public function selectProduct($SeoKey,$ID)
	{
		$ID = parent::checkStrMySQL($ID);
		if(!empty($ID)){
			$SeoKey = parent::checkStrMySQL($SeoKey);
			$str = " WHERE  ID = '".$ID."' ";
		}
		else{
			$str = " WHERE  SeoKey = '".$SeoKey."' ";
		}
		$select = "SELECT * FROM ".products." ".$str." AND `Status`='true' ";
		$query = parent::SelectMySQL($select);
		$row = mysql_fetch_assoc($query);
		parent::CloseConnection();
		
		return $row;
	}
	
}
?>